package com.csun.cmny.provider.service.impl;

import com.csun.cmny.provider.dao.ExpCtrItemMapper;
import com.csun.cmny.provider.dao.ExpenseCtrMapper;
import com.csun.cmny.provider.dto.ExpenseCtrItemQueryDto;
import com.csun.cmny.provider.dto.ShowAllItemDto;
import com.csun.cmny.provider.pojo.ExpCtrItem;
import com.csun.cmny.provider.pojo.ExpenseCtr;
import com.csun.cmny.provider.service.ExpCtrItemService;
import com.csun.cmny.provider.service.ExpenseCtrService;
import com.csun.cmny.provider.vo.ExpenseCtrItemVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("ExpCtrItemService")
public class ExpCtrItemServiceImpl implements ExpCtrItemService {
    @Resource
    ExpCtrItemMapper expCtrItemMapper;

    @Override
    public int insert(ExpCtrItem expCtrItem) {
        return expCtrItemMapper.insertSelective(expCtrItem);
    }

    @Override
    public int delExpCtrItemById(Integer itemId) {
        return expCtrItemMapper.deleteByPrimaryKey(itemId);
    }

    @Override
    public int updateExpCtrById(ExpCtrItem expCtrItem) {
        return expCtrItemMapper.updateByPrimaryKeySelective(expCtrItem);
    }

    @Override
    public ExpCtrItem selectByExpCtrItem(ExpCtrItem expCtrItem) {
        return expCtrItemMapper.selectByExpCtrItem(expCtrItem);
    }

    @Override
    public ExpCtrItem selectById(Integer itemId) {
        return expCtrItemMapper.selectByPrimaryKey(itemId);
    }

    @Override
    public int updateBatch(List<ExpCtrItem> expCtrItemList) {
        return expCtrItemMapper.updateBatch(expCtrItemList);
    }

    @Override
    public int updateBatchSub(List<ExpCtrItem> expCtrItemList) {
        return expCtrItemMapper.updateBatchSub(expCtrItemList);
    }

    @Override
    public List<ExpCtrItem> setlectItemByExpensectrType(Map<String,Object> query) {
        return expCtrItemMapper.setlectItemByExpensectrType(query);
    }

    @Override
    public List<Map<String, Object>> showAll(ShowAllItemDto showAllItemDto) {
        return expCtrItemMapper.showAll(showAllItemDto);
    }

    /**
     * query item list with page
     *
     * @param expenseCtrItemQueryDto expense ctr item query dto
     * @return the page info.
     */
    @Override
    public PageInfo queryItemListWithPage(ExpenseCtrItemQueryDto expenseCtrItemQueryDto) {

        PageHelper.startPage(expenseCtrItemQueryDto.getPageNum(), expenseCtrItemQueryDto.getPageSize());

        List<ExpenseCtrItemVo> expenseCtrItemVoList = expCtrItemMapper.queryItemListWithPage(expenseCtrItemQueryDto);

        return new PageInfo<>(expenseCtrItemVoList);
    }

    /**
     * select oldman item count by item id
     *
     * @param itemId item id
     * @return the int.
     */
    @Override
    public int selectOldmanItemCountByItemId(Integer itemId) {

        return expCtrItemMapper.selectOldmanItemCountByItemId(itemId);
    }

    /**
     * select set meal item count by item id
     *
     * @param itemId item id
     * @return the int.
     */
    @Override
    public int selectSetMealItemCountByItemId(Integer itemId) {

        return expCtrItemMapper.selectSetMealItemCountByItemId(itemId);
    }

    @Override
    public List<Map<String, Object>> isItemBeUsed(Integer itemId, Integer groupId) {
        return expCtrItemMapper.isItemBeUsed(itemId,groupId);
    }

    @Override
    public Integer newIsItemBeUsed(Integer itemId) {
        return expCtrItemMapper.newIsItemBeUsed(itemId);
    }
}
